<template>
  <uni-list v-for="pwd in tableData">
    <uni-list-item class="item" :title="pwd.title" clickable @click="onClick(pwd)" />
  </uni-list>
</template>
<script setup lang="ts">

import { onLoad } from '@dcloudio/uni-app'
import type { PwdInfo } from '@/api/pwd/type'
import { getCurrentInstance, ref } from 'vue'
import { usePwdListStore } from '@/stores'

let pwdListStore = usePwdListStore()

const tableData = ref<PwdInfo[]>()
//@ts-ignore
const { proxy } = getCurrentInstance()
onLoad(async () => {
  await proxy.$onLaunched
  console.log('table onLoad :')
  tableData.value = pwdListStore.getPwdList()
})

pwdListStore.$subscribe((mutate, state) => {
  console.log('pwdListStore.$subscribe', mutate, state)
  tableData.value = pwdListStore.getPwdList()
})


function onClick(pwd: PwdInfo) {
  console.log('执行click事件', pwd)

  uni.navigateTo({
    url: '/pages/detail/index',
    success: function(res) {
      // 通过eventChannel向被打开页面传送数据
      res.eventChannel.emit('pwdDetailEvent', { data: pwd })
    },

  })
}
</script>

<style scoped lang="scss">
.item {
  ::v-deep & * {
    font-size: 17px;
  }
}

</style>